package com.cool.common.model.response;

import lombok.Data;

@Data
public class ResponseResult<T> {
    private String code;
    private String message;
    private T data;
    private long timestamp;

    public ResponseResult() {
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> ResponseResult<T> success() {
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode("0000");
        result.setMessage("成功");
        return result;
    }

    public static <T> ResponseResult<T> success(T data) {
        ResponseResult<T> result = success();
        result.setData(data);
        return result;
    }

    public static <T> ResponseResult<T> fail(String code, String message) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static <T> ResponseResult<T> fail(String code, String message, T data) {
        ResponseResult<T> result = fail(code, message);
        result.setData(data);
        return result;
    }
}
